<section id="content">
  <div class="block">
    <header>
      <h2>&nbsp;</h2>
    </header>
    <!-- HTML5 sekce pro reference -->
    <section class="block-body">
      <?php
      // output messages
      $messages = Session::instance()->get('messages');
      Session::instance()->delete('messages');
      ?>
      <div id="panel-info" <?php if (empty($messages)) {echo 'class="hide"';}?>>
      <div id="panel-info-body">
        <?php
        if (!empty($messages)) {
          foreach ($messages as $type => $messages) {
            foreach ($messages as $message) {
              echo '<p class="' . $type . '"><img src="/media/img/icons/' . $type . '.png" alt="" />' . $message . '</p>';
            }
          }
        }
        ?>
      </div>
      </div>
      <?php if (!isset($dataPost)): ?>
      <script type="text/javascript">
        var pole = new Array();
        var i = 0;
        $(function() {
          $('#file-upload').uploadify({
            'uploader'       : '/media/js/uploadify/uploadify.swf',
            'script'         : '/files/uploadify/',
            'folder'         : '/temp',
            'cancelImg'      : '/media/js/uploadify/cancel.png',
            'multi'          : true,
            'auto'           : false,
            'fileExt'        : '*.jpg',
            'fileDesc'       : 'Image Files (.jpg)',
            'simUploadLimit' : 1,
            'removeCompleted': false,
            'queueID'        : 'custom-queue',
            'buttonImg'   : '/media/js/uploadify/button_cz.gif',
            'height' : 32,
            'width' : 139,
            'scriptData': {'session': '<?php echo Session::instance()->id(); ?>'},
            'onError'     : function (event,ID,fileObj,errorObj) {
              $('#status-message').text(errorObj.type + ' Error: ' + errorObj.info);
            },
            'onSelectOnce'   : function(event,data) {
              $('#status-message').text('Fotografií ve frontě: ' + data.filesSelected);
              $('a#uploadify-upload').css('visibility','visible');
            },
            'onComplete'  : function(event, queueID, fileObj, response, data) {
              var errorOccured = response.substring(0,5).toUpperCase() == "ERROR:";
              if (errorOccured) {
                $("#status-message").html(response.substring(6,response.length));
                return false;
              } else {
                $('#photo-images').insertPhoto(fileObj.filePath);
                pole[i] = [fileObj.name];
                i++;
              }
            },
            'onAllComplete'  : function(event, data) {
              if(data.errors == 0) {
                $('#status-message').text('Úspěšně nahraných souborů: '+ data.filesUploaded);
                $('#uploadify-controls').text('');
                $('#photo-upload').fadeIn();
                $('#src').val(pole);
              }
            }
          });
        });
      </script>
      <div id="uploadify">
        <div id="status-message">Kliknutím vyberte soubory pro upload.</div>
        <div id="custom-queue"></div>
        <div id="uploadify-controls">
          <input id="file-upload" type="file" name="Filedata" />
          <a id="uploadify-upload" class="submit" href="javascript:$('#file-upload').uploadifyUpload()">Nahrát soubory</a>
        </div>
      </div>      
      <div class="clear-both"></div>
      <?php endif ?>
      <div id="photo-upload" <?php if (!isset($dataPost)) { echo 'class="hide"'; } ?>>
        <?php
        if (!isset($dataPost)) {
          $dataPost = array('name' => '', 'src' => '');
        }
        ?>
        <form action="<?php echo url::base(); ?>files/upload_img" method="post" id="form">
          <fieldset>
            <ul>
              <li>
                <label for="name">Název souborů:</label>
                <input type="text" id="name" name="name" value="<?php echo $dataPost['name'] ?>" class="text" />
              </li>
              <li>
              <input type="submit" name="form-submit" value="odeslat"  />
              </li>
              <li>
                <input type="hidden" id="src" name="src" value="<?php echo $dataPost['src'] ?>" class="text" />
              </li>
            </ul>
          </fieldset>
        </form>
      </div>
      <div id="photo-images"></div>
    </section>
  </div>
  <div class="block-bottom"></div>
</section>

